#!/usr/bin/env python3
# coding: utf-8


class Node(object):
    """
    """
    def __init__(self, d):
        self._data = d
        self._next = None

    @property
    def data(self):
        return self._data

    @data.setter
    def data(self, d):
        self._data = d

    @property
    def next(self):
        return self._next

    @next.setter
    def next(self, n):
        self._next = n


class List(object):
    """
    """
    def __init__(self):
        self._head = None

    def add(self, item):
        n = Node(item)
        n.next = self._head
        self._head = n

    @property
    def head(self):
        return self._head

    def __str__(self):
        n = self.head
        ret = ''
        while n:
            ret += '{0}'.format(n.data)
            if n.next:
                ret += ' -> '
            n = n.next
        return ret

    def __len__(self):
        length = 0
        node = self._head
        while not node is None:
            node = node.next
            length += 1
        return length

    def index(self, item):
        i = 0
        n = self.head
        while n:
            if n.data == item:
                return i
            i += 1
            n = n.next
        return -1

    def __contains__(self, item):
        return self.index(item) != -1

    def remove(self, item):
        prev = self.head
        curr = self.head.next
        if item == prev.data:
            self._head = curr
        elif curr:
            while curr.data != item:
                prev = curr
                curr = curr.next
                if curr is None:
                    break
            else:
                prev.next = curr.next

    def pop(self, pos=-1):
        pass


class UnorderedList(List):

    def insert(self, item):
        pass

    def append(self, item):
        if len(self) == 0:
            self._head = Node(item)
        else:
            n = self._head
            while n and n.next:
                n = n.next
            n.next = Node(item)


class OrderedList(List):
    """
    """
    def add(self, item):
        new = Node(item)
        if self.head and self.head.data < item:
            p = self.head
            while p.next and p.next.data < item:
                p = p.next
            new.next = p.next
            p.next = new
        else:
            new.next = self.head
            self._head = new

    def __contains__(self, item):
        pass
